using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SqlWebAdmin.CSharp;
using Smo = Microsoft.SqlServer.Management.Smo;

public partial class CreateStoredProcedure : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

	protected void OnCreateProcedureButtonClick(object sender, EventArgs e)
	{
		Smo.Server smoServer = SmoHelper.GetServer();
		Smo.Database currentDatabase = SmoHelper.GetDatabase();

		try
		{
			currentDatabase.ExecuteNonQuery(sprocText.Text);
			Response.Redirect("StoredProcedures.aspx?Database=" + Request.QueryString["Database"]);
		}
		catch (Microsoft.SqlServer.Management.Smo.SmoException smoEx)
		{
			errorLabel.Text = HttpUtility.HtmlEncode(Common.ConcatenateExceptions(smoEx));
			errorLabel.Visible = true;
		}
		catch (System.Exception ex)
		{
			errorLabel.Visible = true;
			errorLabel.Text = HttpUtility.HtmlEncode(Common.ConcatenateExceptions(ex));
		}
		finally
		{
			smoServer.ConnectionContext.Disconnect();
		}
            
	}
}
